package lab21;

import java.util.Scanner;

public class Brackets {

	private static final char OPEN = '(';
	private static final char CLOSE = ')';

	public static boolean validBrackets(String string) {
		int toClose = 0;
		for (int i = 0; i < string.length(); i++) {
			char current = string.charAt(i);
			if (current == OPEN) {
				toClose++;
			} else if (current == CLOSE) {
				toClose--;
				if (toClose < 0)
					return false;
			} else {
				return false;
			}
		}
		return toClose == 0;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			System.out.println("Enter brackets to check: ");
			String brackets = sc.nextLine();
			System.out.println(validBrackets(brackets));
		}
	}
}